package types

import "strings"

type Classification struct {
	BaseModel
	Uuid       string `json:"uuid"`
	ParentUuid string `json:"parentUuid" form:"parentUuid"`
	Shop       string `json:"shop" form:"shop" binding:"required"`       // 关联店铺
	Name       string `json:"name" form:"name" binding:"required"`       // 名称
	Picture    string `json:"picture" form:"picture" binding:"required"` // 图片
	Notes      string `json:"notes" form:"notes" binding:"required"`     // 介绍
	Order      int    `json:"order" form:"order" binding:"required"`     // 排序
}
type SysClassification struct {
	Classification
	ChildUuids []string            `json:"childUuids" form:"childUuids"`
	Childs     []SysClassification `json:"childs" form:"childs"`
}

func (this_sys *SysClassification) Clone(data *TableClassification) {
	this_sys.Uuid = data.Uuid
	this_sys.ParentUuid = data.ParentUuid
	this_sys.Shop = data.Shop
	this_sys.Name = data.Name
	this_sys.Picture = data.Picture
	this_sys.Notes = data.Notes
	this_sys.Order = data.Order
	if data.ChildUuids != "" {
		this_sys.ChildUuids = strings.Split(data.ChildUuids, ",")
	}

}

type SysClassificationByArr []SysClassification

func (p SysClassificationByArr) Len() int           { return len(p) }
func (p SysClassificationByArr) Less(i, j int) bool { return p[i].Order < p[j].Order }
func (p SysClassificationByArr) Swap(i, j int)      { p[i], p[j] = p[j], p[i] }

type TableClassification struct {
	Classification
	ChildUuids string `json:"childUuids" form:"childUuids"`
}

func (TableClassification) TableName() string {
	return "classification"
}

type ClassificationShop struct {
	ShopUuid string `json:"shopUuid" form:"shopUuid" binding:"required"`
}
